package com.ywz.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 类描述 -> 响应结果工具类
 *
 * @Author: ywz
 * @Date: 2024/09/17
 */
@Data
@AllArgsConstructor
@ApiModel(description = "响应结果")
public class ResultResp {

    @ApiModelProperty(value = "响应码")
    private Integer code;
    @ApiModelProperty(value = "响应信息")
    private String msg;
    @ApiModelProperty(value = "响应数据")
    private Object data;
    public static final int SUCCESS_CODE = 200; // 200表示成功
    public static final int ERROR_CODE = 500; // 500表示失败
    public static final int UNAUTHORIZED_CODE = 401; // 401表示未授权

    public ResultResp(Integer code, String msg) {
        this(code, msg, null);
    }

    public static ResultResp success() {
        return new ResultResp(SUCCESS_CODE, "成功", null);
    }

    public static ResultResp success(Object data) {
        return new ResultResp(SUCCESS_CODE, "成功", data);
    }

    public static ResultResp error() {
        return new ResultResp(ERROR_CODE, "失败", null);
    }

    public static ResultResp error(Object data) {
        return new ResultResp(ERROR_CODE, "失败", data);
    }
}
